home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / dbms_mag / 9103 / cea4.mar < prev    next >
Text File  |  1991-01-28  |  4KB  |  128 lines

  1. /*****************************************************************
  2. *  LastLog.C
  3. *  written by Kathy Cea, Platinum Software Int'l
  4. *
  5. *  InGroup is a utility to list the last login date and time of
  6. *  all network users.
  7. *
  8. *  Calling Syntax:
  9. *     LastLog
  10. *
  11. *   Compiled in Turbo C 2.0 with NetWare C function calls
  12. *
  13. *   Note: This version of the program contains minimal formatting
  14. *         of the output.  It is designed to demonstrate use of
  15. *         the NetWare APIs.  The full version of LastLog.C is
  16. *         available on TelePath.
  17. *****************************************************************/
  18.  
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <nit.h>
  22. #include <niterror.h>
  23. #define MAXNAME 48
  24.  
  25. void getlastlog (char *);
  26. int i,j;
  27.  
  28. main(){
  29.  
  30.     WORD objectType;
  31.     char objectName[MAXNAME];
  32.     long objectId;
  33.     int retcode;
  34.     BYTE propertyValue[128];
  35.     BYTE moreSegs,
  36.          propertyFlags;
  37.     int segNum;
  38.     BYTE temp[3];
  39.     BYTE holdobjId[9];
  40.     char *endptr;
  41.     segNum = 1;
  42.     moreSegs = 255;
  43.  
  44. /* Get all users of group EVERYONE
  45.    Object ID of users are passed back in the propertyValue field
  46.    Up to 32 Object Ids can be returned on each pass.  Continue
  47.    calling ReadPropertyValue until moreSegs is No (0) */
  48.  
  49.     while (moreSegs) {
  50.     retcode = ReadPropertyValue("EVERYONE", OT_USER_GROUP,
  51.                             "GROUP_MEMBERS", segNum,
  52.                             propertyValue, &moreSegs, &propertyFlags);
  53.     segNum++;
  54.  
  55.     /* parse the propertyValue for 4-byte Object IDs,
  56.        then convert each ID to a long integer */
  57.     i = 0;
  58.     temp[2] = '\0';
  59.     holdobjId[0] = '\0';
  60.     while (i < 128) {
  61.         for (j=0; j < 4; j++) {
  62.             /* Build a hex string for each Object ID */
  63.             sprintf(temp, "%02x", propertyValue[i]);
  64.             temp[2] = '\0';
  65.             strcat(holdobjId, temp);
  66.             i++;
  67.         } /* for (j=0; j < 4; j++) */
  68.  
  69.         objectId = strtoul(holdobjId, &endptr, 16);
  70.  
  71.         /* Pass user's Object ID and receive User Name */
  72.         retcode = GetBinderyObjectName(objectId, objectName, &objectType);
  73.         if (!retcode)
  74.             getlastlog(objectName);
  75.         holdobjId[0] = '\0';
  76.     }  /* while (i < 128) */
  77.     } /* while (moreSegs) */
  78. } /* main() */
  79.  
  80. void getlastlog (char objectName[MAXNAME])
  81. /* Gets the last login date & time and the full name for the
  82.     user passed in objectName */
  83.  
  84. {
  85.     WORD objectType;
  86.     int retcode;
  87.     BYTE propertyValue[128];
  88.     BYTE moreSegs,
  89.          propertyFlag;
  90.     char lastlogdt[9];
  91.     char lastlogtm[9];
  92.  
  93.     objectType = OT_USER;
  94.  
  95. /* Read the user's LOGIN_CONTROL property value to obtain the last
  96.    login date & time */
  97.  
  98.     retcode = ReadPropertyValue(objectName, objectType, "LOGIN_CONTROL", 1,
  99.         propertyValue, &moreSegs, &propertyFlag);
  100.     if (!retcode){
  101.         sprintf(lastlogdt,"%02d/%02d/%02d",
  102.                             propertyValue[57],
  103.                             propertyValue[58],
  104.                             propertyValue[56]);
  105.         sprintf(lastlogtm,"%02d:%02d:%02d",
  106.                             propertyValue[59],
  107.                             propertyValue[60],
  108.                             propertyValue[61]);
  109.         lastlogdt[8] = '\0';
  110.         lastlogtm[8] = '\0';
  111.         /* Read the user's IDENTIFICATION property value to obtain the
  112.            full name */
  113.            retcode = ReadPropertyValue(objectName, objectType, "IDENTIFICATION", 1,
  114.                      propertyValue, &moreSegs, &propertyFlag);
  115.             printf("%-20s",objectName);
  116.             printf("%-35s",propertyValue);
  117.             if (!strcmp(lastlogdt,"00/00/00"))
  118.                 printf("No Logins\n");
  119.             else
  120.                 printf("%-8s\t%-8s\n",lastlogdt, lastlogtm);
  121.     } /* if (!retcode) */
  122.     else {
  123.         printf("%-20s",objectName);
  124.         printf("%44s\n","No Logins");
  125.     }
  126.     return;
  127. }
  128.